<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class system_controller extends public_controller
{
    public function backup()
    {
        // Load the DB utility class
        $this->load->dbutil();

        // Backup your entire database and assign it to a variable
        $backup =& $this->dbutil->backup();

        // Load the file helper and write the file to your server
        $this->load->helper('file');
        write_file('backup.gz', $backup);
        force_download('backup.gz',$backup);
        echo 'backup successfully !';
    }

    public function restore()
    {
        $veri = gzfile('backup.gz');
        foreach($veri as $i => $v){
            if(substr($v, 0 ,1) == '#' || trim($v) == '') unset($veri[$i]);
        }
        $yeni = explode(";\n", implode("\n", $veri));
        foreach($yeni as $sql){
            if(trim($sql) != ''){
                $s = $this->db->query(trim($sql));
            }
        }
        echo 'restore successfully !';
    }
}
